{extend name="lib/common_list" /}
{block name="title"}个人中心{/block}
{block name="css"}
    <link rel="stylesheet" href="/static/sys/css/common.css">
{/block}
{block name="javascript"}
<script>
     $(document).ready(function () {
        $("#ok").bind("click", Save);
     })

     function Save() {
        var realname = $.trim($("input[name=real_name]").val());
        if (realname.length == 0) {                
            layer.tips('真实姓名不能为空！', 'input[name=real_name]', { tips: [2, '#78BA32'] });
            return false;
        }
        var password_new = $.trim($("input[name=password_new]").val());
        var password_re = $.trim($("input[name=password_re]").val());
        if (password_new.length || password_re.length) {
            if (password_new.length == 0) {                
                layer.tips('新密码不能为空！', 'input[name=password_new]', { tips: [2, '#78BA32'] });
                return false;
            }  
            if (password_re.length == 0) {                
                layer.tips('确认密码不能为空！', 'input[name=password_re]', { tips: [2, '#78BA32'] });
                return false;
            }else {
                if (password_re !== password_new) {
                    layer.tips('两次密码不一致！', 'input[name=password_re]', { tips: [2, '#78BA32'] });
                    return false;
                }
            }
        }
                 
        $.ajax({
            type: "post",
            url: "{:url('manager/centersave')}",
            data: $("form").serialize(),
            dataType: "json",
            success: function (result) {
                if (result.code === 0) {
                    if (password_new.length && password_re.length) {
                        layer.alert('修改成功！需要重新登录', function() {
                            parent.location.reload();
                        }); 
                    }else {
                        layer.alert('修改成功！', function() {
                            location.reload();
                        }); 
                    }
                }else {
                    layer.alert('修改失败！');
                }
            },
            error:function(xhr,textStatus){
                layer.alert('服务器繁忙！');
            }
        });
    }
</script>
{/block}
{block name="content"}
<div class="main">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form method="post" id="fmNew" class="form-horizontal">
                            <input type="hidden" name="uid" value="{$user.id}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">登录帐号：</label>
                                <div class="col-sm-8">
                                    <input type="text" id="txtusername" value="{$user.user_name}" name="user_name" class="form-control" placeholder="登录帐号" disabled>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><i class="icon-asterisk">*</i>真实姓名：</label>
                                <div class="col-sm-8">
                                    <input type="text" name="real_name" value="{$user.real_name}" class="form-control" placeholder="真实姓名" required>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">新密码：</label>
                                <div class="col-sm-8">
                                    <input type="password" name="password_new" class="form-control" placeholder="新密码">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">确认密码：</label>
                                <div class="col-sm-8">
                                    <input type="password" name="password_re" class="form-control" placeholder="确认密码">
                                </div>
                            </div>                      
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-12 col-sm-offset-5">
                                    <button class="btn btn-primary" id="ok" type="button">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}